%{
#include "stdio.h"
#include "stdlib.h"
%}

INT_DEX [1-9][0-9]*|[0]
INT_HEX [0][Xx]([0-9abcdefABCDEF]+)
FLOAT   ([0]|[1-9][0-9])*[.][0-9]+([Ee][+-]?[0-9]*|[0])?f?
boundary \(|\)|\{|\}|;|\[|\]
opt [+]|[-]|[*]|[/]|[=]|([>][=])|([=][=])|([<][=])|([+][+])|([-][-])|[|]|[^]|[&]|[!]
reserved (while)|(break)|(continue)|(if)|(else)|(float)|(int)|(return)|(void)|(main)
string ([_]|[A-z])+([_]|[0-9]|[A-z])*
whitespace [( )(\n)(\t)] 
error [0-9]+([A-z]|[_])+([A-z]*|[0-9]*|[_]*)*

%%

{error} {
   printf("<  %s,  error>\n", yytext);

}

{INT_DEX}|{INT_HEX}|{FLOAT} {
    printf("<  %s, 常数 >\n", yytext);

}

{whitespace}  {
    

}

{boundary} {
    printf("<  %s, 界符 >\n", yytext);

}

{opt} {
    printf("<  %s, 操作符 >\n", yytext);

}

{reserved} {
    printf("<  %s,  保留字>\n", yytext);

}

{string} {
    printf("<  %s,  标识符>\n", yytext);

}



%%
int yywrap() {
  return 1;
}

int main(int argc, char** argv) {
   if (argc > 1) {
	if (!(yyin = fopen(argv[1], "r"))) {   
           perror(argv[1]);
           return 1;
       }
	}
   while (yylex());
   return 0;
}
